'use strict';

const Service = require('egg').Service;

const nodemailer = require("nodemailer")
const userEmail = "1021965843@qq.com";
const transporter = nodemailer.createTransport({
    service: "qq",
    port: 465,
    secureConnection: true,
    auth: {
        user: userEmail,
        pass: "wtlarkbkpuowbajj"
    }
})

const svgCaptcha = require("svg-captcha")

class ToolsService extends Service {
    async sendEmail(email, title, html) {
        const mailOptions = {
            from: userEmail,
            to: userEmail,
            subject: title,
            text: "",
            html
        }
        try {
            await transporter.sendMail(mailOptions)
            return true
        } catch (error) {
            console.log(error)
            return false
        }
    }

    captcha() {
        const captcha = svgCaptcha.create({
            size: 4,
            fontSize: 50,
            // width: 100,
            height: 40
        })
        return captcha
    }
}


module.exports = ToolsService;